package com.song.mapper;

import com.song.annotation.AutoFill;
import com.song.entity.Setmeal;
import com.song.entity.SetmealDish;
import com.song.enumeration.SqlOperationType;
import com.song.vo.DishItemVO;
import com.song.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SetmealMapper {
    // 查询当前分类下的套餐数量
    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    Integer getMealCountByCategoryId(Long categoryId);

    @Select("select * from setmeal where category_id = #{categoryId}")
    // 根据分类ID查询套餐
    List<Setmeal> getSetmealListByCategoryId(Long categoryId);

    //动态条件查询套餐列表
    List<Setmeal> getSetmealList(Setmeal setmeal);

    // 根据套餐ID查询包含的菜品列表，
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    @AutoFill(SqlOperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);

    // 根据套餐id删除套餐-菜品表中的数据
    @Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
    void deleteSetmealDishBySetmealId(Long setmealId);

    //往套餐-菜品表插入数据
    void insertSetmealDish(List<SetmealDish> setmealDishs);

    // 修改套餐状态
    @Update("update setmeal set status = #{status} where id = #{id}")
    void updateSetmealStatus(Integer status, Long id);

    // 根据套餐ids批量删除套餐
    @Delete("delete from setmeal where id in (#{ids})")
    void deleteSetmealByIds(List<Long> ids);

    // 插入套餐数据
    void insertSetmeal(Setmeal setmeal);

    List<SetmealVO> getSetmealPage(Setmeal setmeal);

    // 根据套餐id查询套餐数据
    @Select("select * from setmeal where id = #{id}")
    List<SetmealDish> getSetmealAnaDish(Long id);

    @Select("select * from setmeal where id = #{id}")
    Setmeal getSetmealById(Long id);
}
